package com.tongda.core.message;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.serialization.ObjectDecoder;
import org.jboss.netty.handler.codec.serialization.ObjectEncoder;

public class MessagePipelineFactory implements ChannelPipelineFactory {
	private MessageListener messageListener;

	public MessagePipelineFactory(MessageListener messageListener) {
		super();
		this.messageListener = messageListener;
	}

	@SuppressWarnings("deprecation")
	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline pipeline = pipeline();

		pipeline.addLast("encode", new ObjectEncoder());
		pipeline.addLast("decode", new ObjectDecoder());

		// add then business logic handler into process chain
		pipeline.addLast("handler", new MessageHandler(messageListener));
		return pipeline;
	}
}
